﻿
namespace System.Security.Cryptography
{
    /// <summary>
    /// Computes a Hash-based Message Authentication Code (HMAC) using the System.Security.Cryptography.SHA1
    /// hash function.
    /// </summary>
    public class HMACSHA1 : HMAC
    {
        /// <summary>
        /// Initializes a new instance of the System.Security.Cryptography.HMACSHA1 class
        /// with the specified key data.
        /// </summary>
        /// <param name="key"></param>
        public HMACSHA1(byte[] key)
            : this(key, false)
        {
        }

        /// <summary>
        /// Initializes a new instance of the System.Security.Cryptography.HMACSHA1 class
        /// with the specified key data and a value that specifies whether to use the
        /// managed version of the SHA1 Algorithm.
        /// </summary>
        /// <param name="key">
        /// The secret key for System.Security.Cryptography.HMACSHA1 encryption. The
        /// key can be any length but if it is more than 64 bytes long, it will be hashed
        /// (using SHA-1) to derive a 64-byte key. Therefore, the recommended size of
        /// the secret key is 64 bytes.
        /// </param>
        /// <param name="useManagedSha1">
        /// true to use the managed implementation of the SHA1 algorithm (the System.Security.Cryptography.SHA1Managed
        /// class); false to use the unmanaged implementation (the System.Security.Cryptography.SHA1CryptoServiceProvider
        /// class).
        /// </param>
        public HMACSHA1(byte[] key, bool useManagedSha1)
        {
            base.hashName = "SHA1";

            if (useManagedSha1)
            {
                base.hash1 = new SHA1Managed();
                base.hash2 = new SHA1Managed();
            }
            else
            {
                base.hash1 = new SHA1CryptoServiceProvider();
                base.hash2 = new SHA1CryptoServiceProvider();
            }

            base.HashSizeValue = 160;
            base.InitializeKey(key);
        }
    }
}
